package design2.chain_of_responsibility.example.middleware;

import design2.chain_of_responsibility.example.server.UserInfo;

/**
 * 检查是否存在具有给定凭据的用户。
 */
public class UserExistsMiddleware extends  Middleware{

	private UserInfo userInfo;

	public UserExistsMiddleware(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	@Override
	public boolean check(String email, String password) {
		if(!userInfo.hasEmail(email)){
			System.out.println("此电子邮件未注册！");
			return  false;
		}

		if(!userInfo.isValidPassword(email, password)){
			System.out.println("密码错误！");
			return  false;
		}

		return checkNext(email, password);
	}
}
